<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-cn" xml:lang="zh-cn">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="DC.Type" content="topic">
  <meta name="DC.Title" content="获取kubeconfig配置文件">
  <meta name="product" content="">
  <meta name="DC.Relation" scheme="URI" content="kubernetes_CSI_00078_2.html">
  <meta name="prodname" content="">
  <meta name="version" content="">
  <meta name="brand" content="30-OceanProtect 备份一体机 1.5.0-1.6.0 帮助中心">
  <meta name="DC.Publisher" content="20240320">
  <meta name="prodname" content="csbs">
  <meta name="documenttype" content="usermanual">
  <meta name="DC.Format" content="XHTML">
  <meta name="DC.Identifier" content="kubernetes_CSI_00078_4">
  <meta name="DC.Language" content="zh-cn">
  <link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
  <title>获取kubeconfig配置文件</title>
 </head>
 <body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px">
  <a name="kubernetes_CSI_00078_4"></a><a name="kubernetes_CSI_00078_4"></a>
  <h1 class="topictitle1">获取kubeconfig配置文件</h1>
  <div>
   <p>当后续需要通过kubeconfig认证的方式注册集群时，可参考本节操作获取kubeconfig配置文件。</p>
   <div class="section">
    <h4 class="sectiontitle">操作步骤</h4>
    <ol>
     <li><span>通过后台登录Kubernetes集群。</span></li>
     <li id="kubernetes_CSI_00078_4__li1722144620173"><span>执行以下命令，使用指定名称创建服务用户。后续步骤以创建的用户名为test进行说明。</span><p></p><pre class="screen" id="kubernetes_CSI_00078_4__screen774314917566">oc create serviceaccount<em id="kubernetes_CSI_00078_4__i15731183210564"> </em><em id="kubernetes_CSI_00078_4__i526717330560">用户名</em></pre> <p></p></li>
     <li id="kubernetes_CSI_00078_4__li2408173142114"><span>执行以下命令，给“test”用户授予“cluster-admin ”角色。</span><p></p><pre class="screen" id="kubernetes_CSI_00078_4__screen1445974610356">oc adm policy add-cluster-role-to-user cluster-admin -z <em id="kubernetes_CSI_00078_4__i166264116452">test</em></pre> <p></p></li>
     <li><span>执行以下命令，设置待导出的Token的参数。其中“duration”参数的值为Token生效时间，以下命令以生效时间10分钟为例。</span><p></p><pre class="screen">export TOKEN=$(oc create token <em>test</em> --duration=<em>600s</em>)</pre> <p></p></li>
     <li><span>执行以下命令，导出kubeconfig配置文件。其中“192.168.0.2:6443”为Kubernetes集群的IP和端口，“/tmp/serviceaccount-kubeconfig”为kubeconfig配置文件的导出路径，可自行定义配置文件的导出路径。</span><p></p><pre class="screen">oc login --server=<em>192.168.0.2:6443</em> --token=$TOKEN --kubeconfig=<em>/tmp/serviceaccount-kubeconfig</em></pre> <p></p></li>
    </ol>
   </div>
  </div>
  <div>
   <div class="familylinks">
    <div class="parentlink">
     <strong>父主题：</strong> <a href="kubernetes_CSI_00078_2.html">备份前准备（适用于OpenShift）</a>
    </div>
   </div>
  </div>
 </body>
</html>